/*
*
* DMode
*
* This class is meant to represent a drawing mode
*
*/
class DMode{
  
  // -----------------------------------------------
  // attributes
  // -----------------------------------------------
  String name, hashName;    // drawing mode display name and name by which it's identified in NHood.metricHash
  float ma, mi, ave;        // minimum, maximum, and average metric values
  ColourTable cTable;       // metricColour table (from giCentre utilities; automatically calculates colour values
  boolean hasMetric;         // descibes whether or not drawing mode has a metric to display
                            // (this will almost always be true, but not for "neighbourhood" display mode)
  int cTableType;           // integer indicating type of preset ColourTable to create
  
  // -----------------------------------------------
  // constructor
  // calculates metric max, min, and ave values
  // -----------------------------------------------
  DMode(String na, NHood[] hoods, int ctt, String hna, boolean hm) {
    
    name = na;
    hashName = hna;
    cTableType = ctt;
    hasMetric = hm;
    
    // if drawing mode has a metric, calculate max, min, and ave
    if(hasMetric) {
      
      float[] metric = new float[hoods.length];
      //int lim = hoods.length;
      int it = 0;
      float sum = 0;

      // iterate through neighbourhoods
      for(int i = 0; i < hoods.length; i++) {

        // retrieve drawing mode's metric from NHood's metricHash
        metric[it] = (Float) hoods[i].metricHash.get(hashName);
        
        // don't store element if it's flagged as having no data
        // if it does have data, add to sum
        if(metric[it] != -1) {
          sum += metric[it];
          it += 1; 
        } else {
          metric = shorten(metric);
        } // if
        
      } // for
      
      // store max, min, ave
      ma = max(metric);
      mi = min(metric);
      ave = sum/metric.length;

    } // if
    
    // create ColourTable using max, min, and colourTable type
    cTable = ColourTable.getPresetColourTable(cTableType, mi, ma);
    
  } // constructor
  
  // -----------------------------------------------
  // getColour
  // returns colour value, given input value
  // -----------------------------------------------
  color getColour(float val) {
    
    // retrive colour from ColourTable
    color out = cTable.findColour(val);
    
    // return colour
    return out;    
    
  } // getColour
  
} // DMode
